package com.carbon.assets.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.bean.copier.ValueProvider;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carbon.assets.common.enums.ProjectStatus;
import com.carbon.assets.entity.*;
import com.carbon.assets.mapper.CarbonMethodologyMapper;
import com.carbon.assets.mapper.CarbonProjectMapper;
import com.carbon.assets.mapper.DictMapper;
import com.carbon.assets.param.*;
import com.carbon.assets.service.CarbonProjectService;
import com.carbon.assets.service.CarbonResourceFileService;
import com.carbon.assets.service.DictService;
import com.carbon.assets.util.ProjectAddUtil;
import com.carbon.assets.vo.*;
import com.carbon.common.enums.ExpCodeEnum;
import com.carbon.common.exception.CommonBizException;
import com.carbon.common.service.BaseServiceImpl;
import com.carbon.common.api.Paging;
import com.carbon.domain.common.ApiResult;
import com.carbon.domain.common.constant.RocketDelayLevelConstant;
import com.carbon.domain.common.constant.RocketMqName;
import com.carbon.domain.mq.entity.OpenRegisterAccount;
import com.carbon.domain.mq.entity.ProjectApproval;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;


/**
 * <p>
 * 碳减排项目 服务实现类
 * </p>
 *
 * @author Li Jun
 * @since 2022-04-24
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class CarbonProjectServiceImpl extends BaseServiceImpl<CarbonProjectMapper, CarbonProject> implements CarbonProjectService {
 @Resource CarbonProjectMapper carbonProjectMapper;
 @Resource
    DictService dictService;


    @Override
    public Page<CarbonProject> selectBySelector(Page<CarbonProject> page, SelectorVo selectorVo) {
        return carbonProjectMapper.selectBySelector(page,selectorVo);
    }

    @Override
    public IPage<CarbonProject> queryProjectList(Page<CarbonProject> pagination, String projectName, Long tenantId) {
        IPage<CarbonProject> carbonProjectIPage = carbonProjectMapper.queryProjectList(pagination, projectName, tenantId);
        List<CarbonProject> records = carbonProjectIPage.getRecords();
        for (CarbonProject record : records) {
            record.setIndustry(dictService.getDictCh(record.getIndustry()));
            record.setProjectStatus(dictService.getDictCh(record.getProjectStatus()));
            record.setCertificationCriteria(dictService.getDictCh(record.getCertificationCriteria()));

        }
        return carbonProjectIPage;
    }

    @Override
    public projectStats fetchProjectStats(String tenantId) {
        return carbonProjectMapper.fetchProjectStats(tenantId);
    }

    @Override
    public List<ProjectByType> fetchTradeData(Long tenantId) {
        return carbonProjectMapper.fetchTradeData(tenantId);
    }
}
